package edu.tec.mty.extras.fuzzy;

//Creates a Gaussian Input Membership Function 
public class InputGaussMF {
	public String variable = "x";
	public String name = "InputGauss"; // Name of the Input Membership Function
									   // for the rules call
	public double sigma = 0.1; //Sigma 
	public double mean = 0.5; //Mean, also as sigma are part of the Gaussian Function
	public double maxRange, minRange;  //Optional max and min Range Values for rounding purposes
	public double output; //Output of the MF
	
	public InputGaussMF(String newname, String var,  double s, double m, double minR, double maxR){
		//GaussFunction throws exception in s <=0
		variable = var;
		name = newname;
		sigma = s;
		mean = m;
		minRange = minR;
		maxRange = maxR;
	}
	
	//Activation evaluates the Membership Function to know the membership value
	public double activation(double input){
		
		if(input < minRange){
			input = minRange;
		}
		if (input > maxRange){
			input = maxRange;
		}
		
		
		try {
		GaussFunction GF = new GaussFunction(sigma, mean);
		
		output = GF.evaluate(input);
		if (output < 0.001){
			output = 0;
		}
		} catch (Exception err) {
			output = 0;
		}
		
		return output;
	}
	
	//Publicate shows the current input
	public String publicate(){
		return variable + " is " + name;
	}		
}
